goog.provide('dkpoints.errors');

goog.require('soy');
goog.require('goog.dom');

goog.require('dkpoints.errors.templates');

dkpoints.errors.name = "/errors";

dkpoints.errors.genericError = function(message) {
    var content = goog.dom.$('body_content');
    soy.renderElement(content, dkpoints.errors.templates.genericError, {message: message});
    
    var button = goog.dom.$('backButton');
    goog.events.listen(button, goog.events.EventType.CLICK,
                       function() {
                        if(window.history.length > 1) {
                          window.history.back();
                        }
                        else {
                          window.location.hash = "";
                        }
                       });
};

dkpoints.errors.http404 = function() {
    var content = goog.dom.$('body_content');
    soy.renderElement(content, dkpoints.errors.templates.http404, {});
    
    var button = goog.dom.$('backButton');
    goog.events.listen(button, goog.events.EventType.CLICK,
                       function() {
                        if(window.history.length > 1) {
                          window.history.back();
                        }
                        else {
                          window.location.hash = "";
                        }
                       });
};

dkpoints.errors.notAuthorized = function(loggedIn) {
    var content = goog.dom.$('body_content');
    soy.renderElement(content, dkpoints.errors.templates.notAuthorized, {loggedIn: loggedIn});
    
    var button = goog.dom.$('backButton');
    goog.events.listen(button, goog.events.EventType.CLICK,
                       function() {
                        if(window.history.length > 1) {
                          window.history.back();
                        }
                        else {
                          window.location.hash = "";
                        }
                       });
}